package com.lzq.chatroom_project.common.config.redis_caffeine_config;


import com.github.benmanes.caffeine.cache.Cache;
import io.lettuce.core.support.caching.CacheAccessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class CaffeineCacheAccessor implements CacheAccessor {
    private static final Logger log = LoggerFactory.getLogger(CaffeineCacheAccessor.class);
    private Cache cache;

    public CaffeineCacheAccessor(Cache cache) {
        this.cache = cache;
    }

    @Override
    public Object get(Object key) {
        log.info("caffeine get => {}", key);
        return cache.getIfPresent(key);
    }

    @Override
    public void put(Object key, Object value) {
        log.info("caffeine set => {}:{}", key, value);
        cache.put(key, value);
    }

    @Override
    public void evict(Object key) {
        log.info("caffeine evict => {}", key);
        cache.invalidate(key);
    }
}
